Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
The mumath npm package provides a collection of mathematical utilities for common operations such as rounding, clamping, and interpolation. It is designed to be lightweight and easy to use for basic mathematical tasks.
Rounding
The rounding feature allows you to round numbers to the nearest integer. The code sample demonstrates rounding 4.6 up to 5 and 4.4 down to 4.
const mumath = require('mumath');
console.log(mumath.round(4.6)); // 5
console.log(mumath.round(4.4)); // 4
Clamping
The clamping feature restricts a number to be within a specified range. The code sample shows clamping 10 to the maximum value of 5 and -1 to the minimum value of 0.
const mumath = require('mumath');
console.log(mumath.clamp(10, 0, 5)); // 5
console.log(mumath.clamp(-1, 0, 5)); // 0
Interpolation
The interpolation feature allows you to find a value at a specific point between two numbers. The code sample demonstrates finding the midpoint (0.5) between 0 and 10, which is 5.
const mumath = require('mumath');
console.log(mumath.lerp(0, 10, 0.5)); // 5
Math.js is an extensive math library for JavaScript and Node.js. It provides a wide range of mathematical functions and supports complex numbers, matrices, and units. Compared to mumath, math.js offers a broader set of features and is suitable for more complex mathematical operations.
Lodash is a utility library that provides functions for common programming tasks, including mathematical operations. It includes methods for rounding, clamping, and interpolation, similar to mumath. However, Lodash is a more comprehensive library that covers a wide range of utilities beyond just math.
Numeral.js is a library for formatting and manipulating numbers. While it focuses more on number formatting and parsing, it also provides some basic mathematical operations. Compared to mumath, Numeral.js is more specialized in number formatting rather than general mathematical utilities.
Set of practical math utils to shorten code.
$ npm install mumath
var round = require('mumath/round');
round(123.32, .5); //123.5
//require any function as
//var <fn> = require('mumath/<fn>');
round(value, precision?)
Rounds value to optional precision
, which is 1
by default.
precision(value)
Get precision from float:
1.1 → 1, 1234 → 0, .1234 → 4
between(value, left, right)
Return value clamped by left/right limits (or vice-versa).
isBetween(value, left, right)
Whether element is between left & right, including.
loop(value, [min,]? max)
An enhanced mod-loop - loops value within a frame.
mult(a, b, ...)
div(a, b, ...)
sub(a, b, ...)
add(a, b, ...)
mod(a, b, ...)
min(a, b, ...)
max(a, b, ...)
floor(a, b, ...)
ceil(a, b, ...)
log(a)
lg(a)
Simple wrappers for arythmetical functions.
gt(a,b)
gte(a,b)
lt(a,b)
lte(a,b)
eq(a,b)
ne(a,b)
Simple conditional functions.
FAQs
Practical math utils for components
The npm package mumath receives a total of 170,949 weekly downloads. As such, mumath popularity was classified as popular.
We found that mumath demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.